///////////////////////////////////////////////////////////////
// File: "CPauseState.cpp"
// Author: James Gonzalez (JG)
// Purpose: The Pause for the game get modified here.
///////////////////////////////////////////////////////////////

#include "CPauseState.h"
#include "CWiimote.h"
#include "../Wrappers/CSGD_DirectInput.h"
#include "CBitmapFontEngine.h"
#include "CMusicManager.h"
#include "CSoundManager.h"
#include "CTransitionScreen.h"
#include "CMainMenuState.h"
#include "..//Wrappers/CSGD_TextureManager.h"
#include "CGame.h"
#include "CLevelSelectState.h"
#include "CGamePlayState.h"
#include "COptionsState.h"
CPauseState::CPauseState(void)
{
	
	m_bExitingToGame = false;
	m_nFontID = -1;
	m_nDimmerID = -1;
	

}

CPauseState::~CPauseState(void)
{
}

void CPauseState::Enter()
{
	//First selected object when you enter the state
	m_nSelection = 0;

	
	m_cScreen.LoadScreen("Screens/BS_PauseScreen.xml");

	m_nFontID = CBitmapFontEngine::GetInstance()->LoadFont("BS_TechDemoTitle.xml");
	m_nDimmerID = CSGD_TextureManager::GetInstance()->LoadTexture("Resource/BS_Pause.png");


	m_bExitingToGame = false;
	m_bExitToLevelSelect = false;

}

void CPauseState::Exit()
{
	m_bExitToLevelSelect = false;
	m_bExitingToGame = false;
}

bool CPauseState::Input(float fElapsedTime)
{
	CWiimote* pWii = CWiimote::GetInstance();
	CSGD_DirectInput* pDI = CSGD_DirectInput::GetInstance();

	if (pWii->IsButtonJustPressed(WII_UP) || pDI->KeyPressed(DIK_UP))
	{
		CSoundManager::GetInstance()->PlaySoundIndxUnBuffered(SOUND_MENU_MOVE);
		--m_nSelection; 
	}
	else if (pWii->IsButtonJustPressed(WII_DOWN) || pDI->KeyPressed(DIK_DOWN))
	{
		CSoundManager::GetInstance()->PlaySoundIndxUnBuffered(SOUND_MENU_MOVE);
		++m_nSelection; 
	}

	if ((pWii->IsButtonJustPressed(WII_A) || pDI->KeyPressed(DIK_RETURN)))
	{
		switch(m_nSelection)
		{
		case RESUME:
			CGame::GetInstance()->PopState();
			break;
		case RESTART:
			CGamePlayState::GetInstance()->RestartLevel();
			CGame::GetInstance()->PopState();
			break;
		case OPTIONS:
			CTransitionScreen::GetInstance()->CloseDoor();
			COptionsState::GetInstance()->SetFromGame(true);
			CGame::GetInstance()->PushState(COptionsState::GetInstance());
			CTransitionScreen::GetInstance()->OpenDoor();
			break;
		case EXIT:
			m_bExitToLevelSelect = true;
			break;;
		}
	}
	if (m_bExitToLevelSelect)
	{
		
		CTransitionScreen::GetInstance()->ChangeTo(CLevelSelectState::GetInstance()); 
	}

	if ((pWii->IsButtonJustPressed(WII_HOME) || pDI->KeyPressed(DIK_ESCAPE)))
	{
		CSoundManager::GetInstance()->PlaySoundIndxUnBuffered(SOUND_MENU_SELECT);
		m_bExitingToGame = true;
	}

	return true;
}

void CPauseState::Update(float fElapsedTime)
{

	if (m_nSelection > EXIT)
		m_nSelection = RESUME;
	else if (m_nSelection < RESUME)
		m_nSelection = EXIT;



	///Close door then change state///////////////////////////////////////////
	if(m_bExitingToGame)
	{
		CGame::GetInstance()->PopState();
	}
	//////////////////////////////////////////////////////////////////////////


}

void CPauseState::Render()
{

	m_cScreen.RenderScreen();
	
	

	//////////////////////////////////////////////////////////////////////////
	//Location Setup
	//////////////////////////////////////////////////////////////////////////
	static const int ResumeX= m_cScreen.GetMenuMembers("Resume",XPOS);
	static const int ResumeY= m_cScreen.GetMenuMembers("Resume",YPOS);

	static const int RestartX = m_cScreen.GetMenuMembers("Restart",XPOS);
	static const int RestartY = m_cScreen.GetMenuMembers("Restart",YPOS);

	static const int OptionsX = m_cScreen.GetMenuMembers("Options",XPOS);
	static const int OptionsY = m_cScreen.GetMenuMembers("Options",YPOS);

	static const int ExitX = m_cScreen.GetMenuMembers("Exit",XPOS);
	static const int ExitY = m_cScreen.GetMenuMembers("Exit",YPOS);

	static const int YELLOW = 0xFFFFFF00;
	static const int WHITE  = 0xFFFFFFFF;
	static const int GREEN =  0xFF00FF00;

	static CBitmapFontEngine* pBFE = CBitmapFontEngine::GetInstance();
	static CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();

	//////////////////////////////////////////////////////////////////////////


	pTM->Draw(m_nDimmerID,0,0,25.0f,18.75f,NULL,0,0,0,0xAA000000);
	

	pBFE->RenderString("Resume",m_nFontID,0,GREEN,ResumeX,ResumeY,0);
	pBFE->RenderString("Restart",m_nFontID,0,GREEN,RestartX,RestartY,0);
	pBFE->RenderString("Options",m_nFontID,0,GREEN,OptionsX,OptionsY,0);
	pBFE->RenderString("Exit",m_nFontID,0,GREEN,ExitX,ExitY,0);


	switch(m_nSelection)
	{
	case RESUME:
		pBFE->RenderString("Resume",m_nFontID,0,YELLOW,ResumeX,ResumeY,0);
		break;
	case RESTART:
		pBFE->RenderString("Restart",m_nFontID,0,YELLOW,RestartX,RestartY,0);
		break;
	case OPTIONS:
		pBFE->RenderString("Options",m_nFontID,0,YELLOW,OptionsX,OptionsY,0);
		break;
	case EXIT:
		pBFE->RenderString("Exit",m_nFontID,0,YELLOW,ExitX,ExitY,0);
		break;
	}

} 
	